import common from '@ohos.app.ability.common';

let map: Map<String, Object> = new Map();

interface ClassForKeyName {
  getKeyName(): string;
  addMockToMap(): any;
}

function addBridgeHandler(o: ClassForKeyName) {
  map.set(o.getKeyName(), o);
}

function getBridgeHandler<T extends ClassForKeyName>(key: T): T {
  if (!map.has(key.getKeyName())) key.addMockToMap()
  return map.get(key.getKeyName()) as T;
}


function tryLoadHap(ctx: common.UIAbilityContext,abilityNameStr:string):Promise<void>{
  let wantInfo = {
    bundleName: ctx.abilityInfo.bundleName,
    abilityName: abilityNameStr,
    parameters: { // 仅加载hap
      onlyLoad:true
    },
  }
  ctx.stageMode
  return ctx.startAbility(wantInfo)
}


export {ClassForKeyName,addBridgeHandler,getBridgeHandler,tryLoadHap}
